<template>
  <div class="legend" :style="{right: getIsHideAssist ? '40px' : '500px'}">
    <div class="legend-word">
      作战图例
      <!--<i class="el-icon-caret-right"></i>-->
    </div>
    <ul>
      <li
        v-for="(item,index) in data"
        :key="item.name"
        @click="buttonItemClick(item,index)"
        :class="{activeLi: item.checked}"
      >
        <i class="legend-icon"></i>
        <span>{{item.name}}</span>
      </li>
    </ul>
    <section class="content-list" v-show="!addCur">
      <header @click="closeList"></header>
      <div class="container">
        <div class="list">
          <div class="team">
            <span>队伍数量</span>
            <i>{{listSize}}</i>
            <font>支</font>
          </div>
          <div class="per">
            <span>总人数</span>
            <i>{{personSum}}</i>
            <font>人</font>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import MapCommon from '@/util/MapCommon';
import YjwzfbStore from '@/store/wsyj/YjdwfbModule/YjdwfbStore';
import { messsageBus } from '../../../../util/message';
import { emergencySever } from '@/api/installServer';
import axios from 'axios';
import qs from 'qs';
@Component({
  mixins: [MapCommon]
})
export default class Legend extends Vue {
  private data = [
    { name: '当地队伍', checked:false, type:"1" },
    { name: '地方队伍', checked:false, type:"2" },
    { name: '部队队伍', checked:false, type:"3" },
  ];
  private addCur = false;
  get teamType() {
    return YjwzfbStore.state.teamType;
  }
  private mounted() {
    // this.getCurrentData();
  }
  private beforeDestroy() {
    YjwzfbStore.state.teamType = '';
  }
  get listSize() {
    return YjwzfbStore.state.currentData.listSize;
  }

  get personSum() {
    return YjwzfbStore.state.currentData.personSum;
  }

  get getIsHideAssist() {
    return this.$store.state['layoutModule' as any].isHideAssist;
  }

  // 图例的点击事件
  private changeLegend(num: any) {
    // this.currentLi = num;
    // 需求更改，第一项由类型1改为查询全部类型置空，二三项为2,3
    if (num == 0) {
      YjwzfbStore.state.teamType = '';
    } else {
      YjwzfbStore.state.teamType = num + 1;
    }
    // this.getCurrentData();
    this.addCur = false;
    (messsageBus as any).$emit('updateListData', event);
  }

  private buttonItemClick( item: any ,index: any ) {
    // 反選邏輯
    if (item.checked === true) {
      item.checked = false;
      YjwzfbStore.state.teamType = '';

      this.addCur = false;
      (messsageBus as any).$emit('updateListData', event);
      return
    } else {
      // 選中邏輯
      // this.state = item.type;
      YjwzfbStore.state.teamType = item.type;
      this.data.forEach((ele: any) => {
        ele.checked = false;
      });
      item.checked = true;
      this.addCur = false;

      (messsageBus as any).$emit('updateListData', event);
      return;
    }
  }
  // private getCurrentData() {
  //   const data = {
  //     teamName: "",
  //     teamType: YjwzfbStore.state.teamType
  //   };
  //   emergencySever.getEmergencyList(qs.stringify(data)).then((res: any) => {
  //     // console.log(res);
  //     if (res.status === 200) {
  //       this.currentData = res.data.data.count;
  //     }
  //   });
  // }
  // 关闭按钮的点击事件
  private closeList() {
    this.addCur = !this.addCur;
  }
}
</script>
<style lang="less">
.legend {
  width: 165px;
  height: 180px;
  padding-top: 30px;
  background: url('../../../../assets/img/legend/legend_bg.png') no-repeat 0 0;
  background-size: 100% 100%;
  background-color: transparent;
  position: absolute;
  bottom: 70px;
  right: 500px;
  .legend-word {
    position: absolute;
    top: -16px;
    right: 11px;
    font-size: 16px;
    line-height: 32px;
    color: #fff;
    text-align: center;
    background: url('../../../../assets/img/legend/legend_word.png') no-repeat 0
      0;
    background-size: 100% 100%;
    width: 120px;
    height: 32px;
    border: 1px solid #00ffff;
    border-radius: 18px;
    i {
      color: #00ffff;
    }
  }
  .activeLi {
    background: url('../../../../assets/img/legend/searchBox.png') no-repeat 30%
      50%;
    background-size: 85% 100%;
    span {
      color: #fff998;
    }
  }
  li {
    position: relative;
    list-style: none;
    cursor: pointer;
    .legend-icon {
      background: url('../../../../assets/img/legend/icon1.png') no-repeat;
      background-size: 100% 100%;
      width: 23px;
      height: 27px;
      position: absolute;
      top: 4px;
      left: -21px;
    }
    span {
      font-size: 20px;
      height: 42px;
      line-height: 42px;
      color: #fff;
      display: inline-block;
      padding-left: 15px;
    }
    i {
      width: 30px;
      height: 30px;
      display: inline-block;
      position: absolute;
      left: 25px;
      margin-top: 6px;
    }
  }
  :nth-of-type(1) .teamIcon {
    background: url('../../../../assets/img/legend/bendi.png') no-repeat;
    background-size: 100% 100%;
  }
  :nth-of-type(2) .teamIcon {
    background: url('../../../../assets/img/legend/difang.png') no-repeat;
    background-size: 100% 100%;
  }
  :nth-of-type(3) .teamIcon {
    background: url('../../../../assets/img/legend/budui.png') no-repeat;
    background-size: 100% 100%;
  }
  li:nth-child(2) {
    .legend-icon {
      background: url('../../../../assets/img/legend/icon2.png') no-repeat;
    }
  }
  li:nth-child(3) {
    .legend-icon {
      background: url('../../../../assets/img/legend/icon3.png') no-repeat;
    }
  }
  header {
    background: url('../../../../assets/img/legend/close.png') no-repeat;
    background-size: 100% 100%;
    width: 50px;
    height: 50px;
    position: absolute;
    bottom: 138px;
    right: 272px;
    z-index: 1;
    cursor: pointer;
  }
  .content-list {
    position: relative;
    .cur {
      display: none;
    }
    .container {
      position: absolute;
      right: 280px;
      bottom: 40px;
    }
    .list {
      font-size: 20px;
      color: #fff;
      span {
        font-size: 26px;
        text-align: center;
        padding-left: 70px;
        padding-right: 40px;
      }
    }
    .team {
      background: url('../../../../assets/img/legend/team.png') no-repeat;
      background-size: 100% 100%;
      width: 370px;
      height: 80px;
      line-height: 80px;
      z-index: 20;
      i {
        font-size: 26px;
        color: #6ad989;
        padding-right: 10px;
      }
    }
    .per {
      background: url('../../../../assets/img/legend/per.png') no-repeat;
      background-size: 100% 100%;
      width: 370px;
      height: 80px;
      line-height: 80px;
      margin-top: -18px;
      i {
        font-size: 26px;
        color: #cc9d45;
        padding-right: 10px;
      }
    }
  }
}
</style>


